package models

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	Title    string  `gorm:"type:varchar(20);comment:'商品名称'"`
	TypesId  int64   `gorm:"type:int(2);default:0;comment:'分类ID'"`
	Price    float32 //价格
	Num      int64   //库存
	Image    string  //商品图片
	CookieId int64
	Status   int64  `gorm:"type:int(1);default:0;comment:'审核状态 1-待审核 2-神话中 3-驳回'"`
	Comment  string //审核备注
}

func (g *Goods) CreateGood(db *gorm.DB) error {
	return db.Create(&g).Error
}

func (g *Goods) UpdateType(db *gorm.DB, goodsId, typeId int64) error {
	return db.Model(&g).Where("id = ?", goodsId).Update("types_id", typeId).Error
}

func (g *Goods) UpdateStatus(db *gorm.DB, goodsId int64) error {
	return db.Model(&g).Where("id = ?", goodsId).Updates(&g).Error
}

type Types struct {
	gorm.Model
	Title    string //分类名称
	CookieId int64  //橱窗ID
}

func (t *Types) CreateTypes(db *gorm.DB) error {
	return db.Create(&t).Error
}

func (t *Types) GetTypesByTitle(db *gorm.DB, title string) error {
	return db.Where("title=?", title).Limit(1).Find(&t).Error
}

type CooKie struct {
	gorm.Model
	Title   string //名称
	UserId  int64  //达人ID
	TypesId int64  //分类IDx
	GoodsId string //首批关联的商品ID
}

func (c *CooKie) CreateCookie(db *gorm.DB) error {
	return db.Create(&c).Error
}

type AskLog struct {
	gorm.Model
	UserId  int64
	GoodsId int64
	Content string
}

func (a *AskLog) CreateAskLog(db *gorm.DB) error {
	return db.Create(&a).Error
}

type Orders struct {
	gorm.Model
	UserId  int64
	OrderSn string
	GoodsId int64
	Status  int64 `gorm:"type:int(1);default:1;comment:'审核状态 1-已下单 2-待支付 3-已失效'"`
}

func (o *Orders) CreateOrder(db *gorm.DB) error {
	return db.Create(&o).Error
}
